<!-- HTML header for doxygen 1.8.20-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
	<meta http-equiv="X-UA-Compatible" content="IE=9"/>
	<meta name="generator" content="Doxygen 1.9.4"/>
	<meta name="viewport" content="width=device-width, initial-scale=1"/>
	<title>Raspberry Pi Pico SDK: include/pico/util/pheap.h Source File</title>
	<!-- <link href="tabs.css" rel="stylesheet" type="text/css"/> -->
	<script type="text/javascript" src="jquery.js"></script>
	<script type="text/javascript" src="dynsections.js"></script>
	<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
	<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
	<link href="doxygen.css" rel="stylesheet" type="text/css" />
	<link href="normalise.css" rel="stylesheet" type="text/css"/>
<link href="main.css" rel="stylesheet" type="text/css"/>
<link href="styles.css" rel="stylesheet" type="text/css"/>
</head>
<body>
	<div class="navigation-mobile">
		<div class="logo--mobile">
			<a href="/"><img src="logo-mobile.svg" alt="Raspberry Pi"></a>
		</div>
		<div class="navigation-toggle">
			<span class="line-1"></span>
			<span class="line-2">
				<p>Menu Toggle</p>
			</span>
			<span class="line-3"></span>
		</div>
	</div>
	<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
		<div class="logo">
			<a href="index.html"> <img src="logo.svg" alt="Raspberry Pi"></a>
			<span style="display: inline-block; margin-top: 10px;">
				v2.0.0
			</span>
		</div>
		<div class="navigation-footer">
			<img src="logo-mobile.svg" alt="Raspberry Pi">
			<a href="https://www.raspberrypi.com/" target="_blank">By Raspberry Pi Ltd</a>
		</div>
<!-- 		<div class="search">
			<form>
				<input type="search" name="search" id="search" placeholder="Search">
				<input type="submit" value="Search">
			</form>
		</div> -->
<!-- Generated by Doxygen 1.9.4 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search",'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('pheap_8h_source.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle"><div class="title">pheap.h</div></div>
</div><!--header-->
<div class="contents">
<a href="pheap_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno">    1</span><span class="comment">/*</span></div>
<div class="line"><a id="l00002" name="l00002"></a><span class="lineno">    2</span><span class="comment"> * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.</span></div>
<div class="line"><a id="l00003" name="l00003"></a><span class="lineno">    3</span><span class="comment"> *</span></div>
<div class="line"><a id="l00004" name="l00004"></a><span class="lineno">    4</span><span class="comment"> * SPDX-License-Identifier: BSD-3-Clause</span></div>
<div class="line"><a id="l00005" name="l00005"></a><span class="lineno">    5</span><span class="comment"> */</span></div>
<div class="line"><a id="l00006" name="l00006"></a><span class="lineno">    6</span> </div>
<div class="line"><a id="l00007" name="l00007"></a><span class="lineno">    7</span><span class="preprocessor">#ifndef _PICO_UTIL_PHEAP_H</span></div>
<div class="line"><a id="l00008" name="l00008"></a><span class="lineno">    8</span><span class="preprocessor">#define _PICO_UTIL_PHEAP_H</span></div>
<div class="line"><a id="l00009" name="l00009"></a><span class="lineno">    9</span> </div>
<div class="line"><a id="l00010" name="l00010"></a><span class="lineno">   10</span><span class="preprocessor">#include &quot;<a class="code" href="pico_8h.html">pico.h</a>&quot;</span></div>
<div class="line"><a id="l00011" name="l00011"></a><span class="lineno">   11</span> </div>
<div class="line"><a id="l00012" name="l00012"></a><span class="lineno">   12</span><span class="preprocessor">#ifdef __cplusplus</span></div>
<div class="line"><a id="l00013" name="l00013"></a><span class="lineno">   13</span><span class="keyword">extern</span> <span class="stringliteral">&quot;C&quot;</span> {</div>
<div class="line"><a id="l00014" name="l00014"></a><span class="lineno">   14</span><span class="preprocessor">#endif</span></div>
<div class="line"><a id="l00015" name="l00015"></a><span class="lineno">   15</span> </div>
<div class="line"><a id="l00016" name="l00016"></a><span class="lineno">   16</span><span class="comment">// PICO_CONFIG: PARAM_ASSERTIONS_ENABLED_PHEAP, Enable/disable assertions in the pheap module, type=bool, default=0, group=pico_util</span></div>
<div class="line"><a id="l00017" name="l00017"></a><span class="lineno">   17</span><span class="preprocessor">#ifndef PARAM_ASSERTIONS_ENABLED_PHEAP</span></div>
<div class="line"><a id="l00018" name="l00018"></a><span class="lineno">   18</span><span class="preprocessor">#define PARAM_ASSERTIONS_ENABLED_PHEAP 0</span></div>
<div class="line"><a id="l00019" name="l00019"></a><span class="lineno">   19</span><span class="preprocessor">#endif</span></div>
<div class="line"><a id="l00020" name="l00020"></a><span class="lineno">   20</span> </div>
<div class="line"><a id="l00037" name="l00037"></a><span class="lineno">   37</span><span class="comment">// PICO_CONFIG: PICO_PHEAP_MAX_ENTRIES, Maximum number of entries in the pheap, min=1, max=65534, default=255, group=pico_util</span></div>
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno">   38</span><span class="preprocessor">#ifndef PICO_PHEAP_MAX_ENTRIES</span></div>
<div class="line"><a id="l00039" name="l00039"></a><span class="lineno">   39</span><span class="preprocessor">#define PICO_PHEAP_MAX_ENTRIES 255</span></div>
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno">   40</span><span class="preprocessor">#endif</span></div>
<div class="line"><a id="l00041" name="l00041"></a><span class="lineno">   41</span> </div>
<div class="line"><a id="l00042" name="l00042"></a><span class="lineno">   42</span><span class="comment">// public heap_node ids are numbered from 1 (0 means none)</span></div>
<div class="line"><a id="l00043" name="l00043"></a><span class="lineno">   43</span><span class="preprocessor">#if PICO_PHEAP_MAX_ENTRIES &lt; 256</span></div>
<div class="line"><a id="l00044" name="l00044"></a><span class="lineno">   44</span><span class="keyword">typedef</span> uint8_t pheap_node_id_t;</div>
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno">   45</span><span class="preprocessor">#elif PICO_PHEAP_MAX_ENTRIES &lt; 65535</span></div>
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno">   46</span><span class="keyword">typedef</span> uint16_t pheap_node_id_t;</div>
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno">   47</span><span class="preprocessor">#else</span></div>
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno">   48</span><span class="preprocessor">#error invalid PICO_PHEAP_MAX_ENTRIES</span></div>
<div class="line"><a id="l00049" name="l00049"></a><span class="lineno">   49</span><span class="preprocessor">#endif</span></div>
<div class="line"><a id="l00050" name="l00050"></a><span class="lineno">   50</span> </div>
<div class="line"><a id="l00051" name="l00051"></a><span class="lineno"><a class="line" href="structpheap__node.html">   51</a></span><span class="keyword">typedef</span> <span class="keyword">struct </span><a class="code hl_struct" href="structpheap__node.html">pheap_node</a> {</div>
<div class="line"><a id="l00052" name="l00052"></a><span class="lineno">   52</span>    pheap_node_id_t child, sibling, parent;</div>
<div class="line"><a id="l00053" name="l00053"></a><span class="lineno">   53</span>} <a class="code hl_struct" href="structpheap__node.html">pheap_node_t</a>;</div>
<div class="line"><a id="l00054" name="l00054"></a><span class="lineno">   54</span> </div>
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno"><a class="line" href="pheap_8h.html#a0656dff462e9c9b41b60b7c86ba39f09">   60</a></span><span class="keyword">typedef</span> bool (*<a class="code hl_typedef" href="pheap_8h.html#a0656dff462e9c9b41b60b7c86ba39f09">pheap_comparator</a>)(<span class="keywordtype">void</span> *user_data, pheap_node_id_t a, pheap_node_id_t b);</div>
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno">   61</span> </div>
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno"><a class="line" href="structpheap.html">   62</a></span><span class="keyword">typedef</span> <span class="keyword">struct </span><a class="code hl_struct" href="structpheap.html">pheap</a> {</div>
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno">   63</span>    <a class="code hl_struct" href="structpheap__node.html">pheap_node_t</a> *nodes;</div>
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno">   64</span>    <a class="code hl_typedef" href="pheap_8h.html#a0656dff462e9c9b41b60b7c86ba39f09">pheap_comparator</a> comparator;</div>
<div class="line"><a id="l00065" name="l00065"></a><span class="lineno">   65</span>    <span class="keywordtype">void</span> *user_data;</div>
<div class="line"><a id="l00066" name="l00066"></a><span class="lineno">   66</span>    pheap_node_id_t max_nodes;</div>
<div class="line"><a id="l00067" name="l00067"></a><span class="lineno">   67</span>    pheap_node_id_t root_id;</div>
<div class="line"><a id="l00068" name="l00068"></a><span class="lineno">   68</span>    <span class="comment">// we remove from head and add to tail to stop reusing the same ids</span></div>
<div class="line"><a id="l00069" name="l00069"></a><span class="lineno">   69</span>    pheap_node_id_t free_head_id;</div>
<div class="line"><a id="l00070" name="l00070"></a><span class="lineno">   70</span>    pheap_node_id_t free_tail_id;</div>
<div class="line"><a id="l00071" name="l00071"></a><span class="lineno">   71</span>} <a class="code hl_struct" href="structpheap.html">pheap_t</a>;</div>
<div class="line"><a id="l00072" name="l00072"></a><span class="lineno">   72</span> </div>
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno">   86</span><a class="code hl_struct" href="structpheap.html">pheap_t</a> *<a class="code hl_function" href="pheap_8h.html#acde2f3fabd67330b56dbb8473387b272">ph_create</a>(uint max_nodes, <a class="code hl_typedef" href="pheap_8h.html#a0656dff462e9c9b41b60b7c86ba39f09">pheap_comparator</a> comparator, <span class="keywordtype">void</span> *user_data);</div>
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno">   87</span> </div>
<div class="line"><a id="l00092" name="l00092"></a><span class="lineno">   92</span><span class="keywordtype">void</span> <a class="code hl_function" href="pheap_8h.html#a1fe718acebd018d31cab37071a65c61b">ph_clear</a>(<a class="code hl_struct" href="structpheap.html">pheap_t</a> *heap);</div>
<div class="line"><a id="l00093" name="l00093"></a><span class="lineno">   93</span> </div>
<div class="line"><a id="l00100" name="l00100"></a><span class="lineno">  100</span><span class="keywordtype">void</span> <a class="code hl_function" href="pheap_8h.html#a0ad42a7be2446ffcdbce6c9c3590eb8e">ph_destroy</a>(<a class="code hl_struct" href="structpheap.html">pheap_t</a> *heap);</div>
<div class="line"><a id="l00101" name="l00101"></a><span class="lineno">  101</span> </div>
<div class="line"><a id="l00102" name="l00102"></a><span class="lineno">  102</span><span class="comment">// internal method</span></div>
<div class="line"><a id="l00103" name="l00103"></a><span class="lineno">  103</span><span class="keyword">static</span> <span class="keyword">inline</span> <a class="code hl_struct" href="structpheap__node.html">pheap_node_t</a> *ph_get_node(<a class="code hl_struct" href="structpheap.html">pheap_t</a> *heap, pheap_node_id_t <span class="keywordtype">id</span>) {</div>
<div class="line"><a id="l00104" name="l00104"></a><span class="lineno">  104</span>    assert(<span class="keywordtype">id</span> &amp;&amp; id &lt;= heap-&gt;max_nodes);</div>
<div class="line"><a id="l00105" name="l00105"></a><span class="lineno">  105</span>    <span class="keywordflow">return</span> heap-&gt;nodes + <span class="keywordtype">id</span> - 1;</div>
<div class="line"><a id="l00106" name="l00106"></a><span class="lineno">  106</span>}</div>
<div class="line"><a id="l00107" name="l00107"></a><span class="lineno">  107</span> </div>
<div class="line"><a id="l00108" name="l00108"></a><span class="lineno">  108</span><span class="comment">// internal method</span></div>
<div class="line"><a id="l00109" name="l00109"></a><span class="lineno">  109</span><span class="keyword">static</span> <span class="keywordtype">void</span> ph_add_child_node(<a class="code hl_struct" href="structpheap.html">pheap_t</a> *heap, pheap_node_id_t parent_id, pheap_node_id_t child_id) {</div>
<div class="line"><a id="l00110" name="l00110"></a><span class="lineno">  110</span>    <a class="code hl_struct" href="structpheap__node.html">pheap_node_t</a> *n = ph_get_node(heap, parent_id);</div>
<div class="line"><a id="l00111" name="l00111"></a><span class="lineno">  111</span>    assert(parent_id);</div>
<div class="line"><a id="l00112" name="l00112"></a><span class="lineno">  112</span>    assert(child_id);</div>
<div class="line"><a id="l00113" name="l00113"></a><span class="lineno">  113</span>    assert(parent_id != child_id);</div>
<div class="line"><a id="l00114" name="l00114"></a><span class="lineno">  114</span>    <a class="code hl_struct" href="structpheap__node.html">pheap_node_t</a> *c = ph_get_node(heap, child_id);</div>
<div class="line"><a id="l00115" name="l00115"></a><span class="lineno">  115</span>    c-&gt;parent = parent_id;</div>
<div class="line"><a id="l00116" name="l00116"></a><span class="lineno">  116</span>    <span class="keywordflow">if</span> (!n-&gt;child) {</div>
<div class="line"><a id="l00117" name="l00117"></a><span class="lineno">  117</span>        n-&gt;child = child_id;</div>
<div class="line"><a id="l00118" name="l00118"></a><span class="lineno">  118</span>    } <span class="keywordflow">else</span> {</div>
<div class="line"><a id="l00119" name="l00119"></a><span class="lineno">  119</span>        c-&gt;sibling = n-&gt;child;</div>
<div class="line"><a id="l00120" name="l00120"></a><span class="lineno">  120</span>        n-&gt;child = child_id;</div>
<div class="line"><a id="l00121" name="l00121"></a><span class="lineno">  121</span>    }</div>
<div class="line"><a id="l00122" name="l00122"></a><span class="lineno">  122</span>}</div>
<div class="line"><a id="l00123" name="l00123"></a><span class="lineno">  123</span> </div>
<div class="line"><a id="l00124" name="l00124"></a><span class="lineno">  124</span><span class="comment">// internal method</span></div>
<div class="line"><a id="l00125" name="l00125"></a><span class="lineno">  125</span><span class="keyword">static</span> pheap_node_id_t ph_merge_nodes(<a class="code hl_struct" href="structpheap.html">pheap_t</a> *heap, pheap_node_id_t a, pheap_node_id_t b) {</div>
<div class="line"><a id="l00126" name="l00126"></a><span class="lineno">  126</span>    <span class="keywordflow">if</span> (!a) <span class="keywordflow">return</span> b;</div>
<div class="line"><a id="l00127" name="l00127"></a><span class="lineno">  127</span>    <span class="keywordflow">if</span> (!b) <span class="keywordflow">return</span> a;</div>
<div class="line"><a id="l00128" name="l00128"></a><span class="lineno">  128</span>    <span class="keywordflow">if</span> (heap-&gt;comparator(heap-&gt;user_data, a, b)) {</div>
<div class="line"><a id="l00129" name="l00129"></a><span class="lineno">  129</span>        ph_add_child_node(heap, a, b);</div>
<div class="line"><a id="l00130" name="l00130"></a><span class="lineno">  130</span>        <span class="keywordflow">return</span> a;</div>
<div class="line"><a id="l00131" name="l00131"></a><span class="lineno">  131</span>    } <span class="keywordflow">else</span> {</div>
<div class="line"><a id="l00132" name="l00132"></a><span class="lineno">  132</span>        ph_add_child_node(heap, b, a);</div>
<div class="line"><a id="l00133" name="l00133"></a><span class="lineno">  133</span>        <span class="keywordflow">return</span> b;</div>
<div class="line"><a id="l00134" name="l00134"></a><span class="lineno">  134</span>    }</div>
<div class="line"><a id="l00135" name="l00135"></a><span class="lineno">  135</span>}</div>
<div class="line"><a id="l00136" name="l00136"></a><span class="lineno">  136</span> </div>
<div class="line"><a id="l00143" name="l00143"></a><span class="lineno"><a class="line" href="pheap_8h.html#af631622b2fe9dbd39f39d457eef502d0">  143</a></span><span class="keyword">static</span> <span class="keyword">inline</span> pheap_node_id_t <a class="code hl_function" href="pheap_8h.html#af631622b2fe9dbd39f39d457eef502d0">ph_new_node</a>(<a class="code hl_struct" href="structpheap.html">pheap_t</a> *heap) {</div>
<div class="line"><a id="l00144" name="l00144"></a><span class="lineno">  144</span>    <span class="keywordflow">if</span> (!heap-&gt;free_head_id) <span class="keywordflow">return</span> 0;</div>
<div class="line"><a id="l00145" name="l00145"></a><span class="lineno">  145</span>    pheap_node_id_t <span class="keywordtype">id</span> = heap-&gt;free_head_id;</div>
<div class="line"><a id="l00146" name="l00146"></a><span class="lineno">  146</span>    <a class="code hl_struct" href="structpheap__node.html">pheap_node_t</a> *hn = ph_get_node(heap, <span class="keywordtype">id</span>);</div>
<div class="line"><a id="l00147" name="l00147"></a><span class="lineno">  147</span>    heap-&gt;free_head_id = hn-&gt;sibling;</div>
<div class="line"><a id="l00148" name="l00148"></a><span class="lineno">  148</span>    <span class="keywordflow">if</span> (!heap-&gt;free_head_id) heap-&gt;free_tail_id = 0;</div>
<div class="line"><a id="l00149" name="l00149"></a><span class="lineno">  149</span>    hn-&gt;child = hn-&gt;sibling = hn-&gt;parent = 0;</div>
<div class="line"><a id="l00150" name="l00150"></a><span class="lineno">  150</span>    <span class="keywordflow">return</span> id;</div>
<div class="line"><a id="l00151" name="l00151"></a><span class="lineno">  151</span>}</div>
<div class="line"><a id="l00152" name="l00152"></a><span class="lineno">  152</span> </div>
<div class="line"><a id="l00164" name="l00164"></a><span class="lineno"><a class="line" href="pheap_8h.html#ab68363a744cae76cf6cce07fc60f4a5c">  164</a></span><span class="keyword">static</span> <span class="keyword">inline</span> pheap_node_id_t <a class="code hl_function" href="pheap_8h.html#ab68363a744cae76cf6cce07fc60f4a5c">ph_insert_node</a>(<a class="code hl_struct" href="structpheap.html">pheap_t</a> *heap, pheap_node_id_t <span class="keywordtype">id</span>) {</div>
<div class="line"><a id="l00165" name="l00165"></a><span class="lineno">  165</span>    assert(<span class="keywordtype">id</span>);</div>
<div class="line"><a id="l00166" name="l00166"></a><span class="lineno">  166</span>    <a class="code hl_struct" href="structpheap__node.html">pheap_node_t</a> *hn = ph_get_node(heap, <span class="keywordtype">id</span>);</div>
<div class="line"><a id="l00167" name="l00167"></a><span class="lineno">  167</span>    hn-&gt;child = hn-&gt;sibling = hn-&gt;parent = 0;</div>
<div class="line"><a id="l00168" name="l00168"></a><span class="lineno">  168</span>    heap-&gt;root_id = ph_merge_nodes(heap, heap-&gt;root_id, <span class="keywordtype">id</span>);</div>
<div class="line"><a id="l00169" name="l00169"></a><span class="lineno">  169</span>    <span class="keywordflow">return</span> heap-&gt;root_id;</div>
<div class="line"><a id="l00170" name="l00170"></a><span class="lineno">  170</span>}</div>
<div class="line"><a id="l00171" name="l00171"></a><span class="lineno">  171</span> </div>
<div class="line"><a id="l00179" name="l00179"></a><span class="lineno"><a class="line" href="pheap_8h.html#a9723f40e88f36de3cd6cd955e3410600">  179</a></span><span class="keyword">static</span> <span class="keyword">inline</span> pheap_node_id_t <a class="code hl_function" href="pheap_8h.html#a9723f40e88f36de3cd6cd955e3410600">ph_peek_head</a>(<a class="code hl_struct" href="structpheap.html">pheap_t</a> *heap) {</div>
<div class="line"><a id="l00180" name="l00180"></a><span class="lineno">  180</span>    <span class="keywordflow">return</span> heap-&gt;root_id;</div>
<div class="line"><a id="l00181" name="l00181"></a><span class="lineno">  181</span>}</div>
<div class="line"><a id="l00182" name="l00182"></a><span class="lineno">  182</span> </div>
<div class="line"><a id="l00198" name="l00198"></a><span class="lineno">  198</span>pheap_node_id_t <a class="code hl_function" href="pheap_8h.html#a8ebc494b4ad703fe080bee5f18775fec">ph_remove_head</a>(<a class="code hl_struct" href="structpheap.html">pheap_t</a> *heap, <span class="keywordtype">bool</span> free);</div>
<div class="line"><a id="l00199" name="l00199"></a><span class="lineno">  199</span> </div>
<div class="line"><a id="l00212" name="l00212"></a><span class="lineno"><a class="line" href="pheap_8h.html#aee7c4944ce644b92572b48b7d14fc65e">  212</a></span><span class="keyword">static</span> <span class="keyword">inline</span> pheap_node_id_t <a class="code hl_function" href="pheap_8h.html#aee7c4944ce644b92572b48b7d14fc65e">ph_remove_and_free_head</a>(<a class="code hl_struct" href="structpheap.html">pheap_t</a> *heap) {</div>
<div class="line"><a id="l00213" name="l00213"></a><span class="lineno">  213</span>    <span class="keywordflow">return</span> <a class="code hl_function" href="pheap_8h.html#a8ebc494b4ad703fe080bee5f18775fec">ph_remove_head</a>(heap, <span class="keyword">true</span>);</div>
<div class="line"><a id="l00214" name="l00214"></a><span class="lineno">  214</span>}</div>
<div class="line"><a id="l00215" name="l00215"></a><span class="lineno">  215</span> </div>
<div class="line"><a id="l00224" name="l00224"></a><span class="lineno">  224</span><span class="keywordtype">bool</span> <a class="code hl_function" href="pheap_8h.html#a852301ee2d8d4c3985dd61c14eb820a8">ph_remove_and_free_node</a>(<a class="code hl_struct" href="structpheap.html">pheap_t</a> *heap, pheap_node_id_t <span class="keywordtype">id</span>);</div>
<div class="line"><a id="l00225" name="l00225"></a><span class="lineno">  225</span> </div>
<div class="line"><a id="l00234" name="l00234"></a><span class="lineno"><a class="line" href="pheap_8h.html#a799a2b5a1db608401482816d371a02a5">  234</a></span><span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code hl_function" href="pheap_8h.html#a799a2b5a1db608401482816d371a02a5">ph_contains_node</a>(<a class="code hl_struct" href="structpheap.html">pheap_t</a> *heap, pheap_node_id_t <span class="keywordtype">id</span>) {</div>
<div class="line"><a id="l00235" name="l00235"></a><span class="lineno">  235</span>    <span class="keywordflow">return</span> <span class="keywordtype">id</span> == heap-&gt;root_id || ph_get_node(heap, <span class="keywordtype">id</span>)-&gt;parent;</div>
<div class="line"><a id="l00236" name="l00236"></a><span class="lineno">  236</span>}</div>
<div class="line"><a id="l00237" name="l00237"></a><span class="lineno">  237</span> </div>
<div class="line"><a id="l00238" name="l00238"></a><span class="lineno">  238</span> </div>
<div class="line"><a id="l00245" name="l00245"></a><span class="lineno"><a class="line" href="pheap_8h.html#a16d2f59279aad9419ebab05bf15d70b2">  245</a></span><span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code hl_function" href="pheap_8h.html#a16d2f59279aad9419ebab05bf15d70b2">ph_free_node</a>(<a class="code hl_struct" href="structpheap.html">pheap_t</a> *heap, pheap_node_id_t <span class="keywordtype">id</span>) {</div>
<div class="line"><a id="l00246" name="l00246"></a><span class="lineno">  246</span>    assert(<span class="keywordtype">id</span> &amp;&amp; !<a class="code hl_function" href="pheap_8h.html#a799a2b5a1db608401482816d371a02a5">ph_contains_node</a>(heap, <span class="keywordtype">id</span>));</div>
<div class="line"><a id="l00247" name="l00247"></a><span class="lineno">  247</span>    <span class="keywordflow">if</span> (heap-&gt;free_tail_id) {</div>
<div class="line"><a id="l00248" name="l00248"></a><span class="lineno">  248</span>        ph_get_node(heap, heap-&gt;free_tail_id)-&gt;sibling = id;</div>
<div class="line"><a id="l00249" name="l00249"></a><span class="lineno">  249</span>    }</div>
<div class="line"><a id="l00250" name="l00250"></a><span class="lineno">  250</span>    <span class="keywordflow">if</span> (!heap-&gt;free_head_id) {</div>
<div class="line"><a id="l00251" name="l00251"></a><span class="lineno">  251</span>        assert(!heap-&gt;free_tail_id);</div>
<div class="line"><a id="l00252" name="l00252"></a><span class="lineno">  252</span>        heap-&gt;free_head_id = id;</div>
<div class="line"><a id="l00253" name="l00253"></a><span class="lineno">  253</span>    }</div>
<div class="line"><a id="l00254" name="l00254"></a><span class="lineno">  254</span>    heap-&gt;free_tail_id = id;</div>
<div class="line"><a id="l00255" name="l00255"></a><span class="lineno">  255</span>}</div>
<div class="line"><a id="l00256" name="l00256"></a><span class="lineno">  256</span> </div>
<div class="line"><a id="l00264" name="l00264"></a><span class="lineno"><a class="line" href="pheap_8h.html#aaac9dd2a264364a16a5753ba08c268cf">  264</a></span><span class="keywordtype">void</span> <a class="code hl_function" href="pheap_8h.html#aaac9dd2a264364a16a5753ba08c268cf">ph_dump</a>(<a class="code hl_struct" href="structpheap.html">pheap_t</a> *heap, <span class="keywordtype">void</span> (*dump_key)(pheap_node_id_t <span class="keywordtype">id</span>, <span class="keywordtype">void</span> *user_data), <span class="keywordtype">void</span> *user_data);</div>
<div class="line"><a id="l00265" name="l00265"></a><span class="lineno">  265</span> </div>
<div class="line"><a id="l00275" name="l00275"></a><span class="lineno">  275</span><span class="keywordtype">void</span> <a class="code hl_function" href="pheap_8h.html#a5f8a3b950288b90310216126750ae0ef">ph_post_alloc_init</a>(<a class="code hl_struct" href="structpheap.html">pheap_t</a> *heap, uint max_nodes, <a class="code hl_typedef" href="pheap_8h.html#a0656dff462e9c9b41b60b7c86ba39f09">pheap_comparator</a> comparator, <span class="keywordtype">void</span> *user_data);</div>
<div class="line"><a id="l00276" name="l00276"></a><span class="lineno">  276</span> </div>
<div class="line"><a id="l00281" name="l00281"></a><span class="lineno"><a class="line" href="pheap_8h.html#a9b69785185d58a5f82204c9ee3c2a2d5">  281</a></span><span class="preprocessor">#define PHEAP_DEFINE_STATIC(name, _max_nodes) \</span></div>
<div class="line"><a id="l00282" name="l00282"></a><span class="lineno">  282</span><span class="preprocessor">    static_assert(_max_nodes &amp;&amp; _max_nodes &lt; (1u &lt;&lt; (8 * sizeof(pheap_node_id_t))), &quot;&quot;</span>); \</div>
<div class="line"><a id="l00283" name="l00283"></a><span class="lineno">  283</span>    static pheap_node_t name ## _nodes[_max_nodes]; \</div>
<div class="line"><a id="l00284" name="l00284"></a><span class="lineno">  284</span>    static pheap_t name = { \</div>
<div class="line"><a id="l00285" name="l00285"></a><span class="lineno">  285</span>            .nodes = name ## _nodes, \</div>
<div class="line"><a id="l00286" name="l00286"></a><span class="lineno">  286</span>            .max_nodes = _max_nodes \</div>
<div class="line"><a id="l00287" name="l00287"></a><span class="lineno">  287</span>    };</div>
<div class="line"><a id="l00288" name="l00288"></a><span class="lineno">  288</span> </div>
<div class="line"><a id="l00289" name="l00289"></a><span class="lineno">  289</span> </div>
<div class="line"><a id="l00290" name="l00290"></a><span class="lineno">  290</span><span class="preprocessor">#ifdef __cplusplus</span></div>
<div class="line"><a id="l00291" name="l00291"></a><span class="lineno">  291</span>}</div>
<div class="line"><a id="l00292" name="l00292"></a><span class="lineno">  292</span><span class="preprocessor">#endif</span></div>
<div class="line"><a id="l00293" name="l00293"></a><span class="lineno">  293</span> </div>
<div class="line"><a id="l00294" name="l00294"></a><span class="lineno">  294</span><span class="preprocessor">#endif</span></div>
<div class="ttc" id="apheap_8h_html_a0656dff462e9c9b41b60b7c86ba39f09"><div class="ttname"><a href="pheap_8h.html#a0656dff462e9c9b41b60b7c86ba39f09">pheap_comparator</a></div><div class="ttdeci">bool(* pheap_comparator)(void *user_data, pheap_node_id_t a, pheap_node_id_t b)</div><div class="ttdoc">A user comparator function for nodes in a pairing heap.</div><div class="ttdef"><b>Definition:</b> pheap.h:60</div></div>
<div class="ttc" id="apheap_8h_html_a0ad42a7be2446ffcdbce6c9c3590eb8e"><div class="ttname"><a href="pheap_8h.html#a0ad42a7be2446ffcdbce6c9c3590eb8e">ph_destroy</a></div><div class="ttdeci">void ph_destroy(pheap_t *heap)</div><div class="ttdoc">De-allocates a pairing heap.</div><div class="ttdef"><b>Definition:</b> pheap.c:37</div></div>
<div class="ttc" id="apheap_8h_html_a16d2f59279aad9419ebab05bf15d70b2"><div class="ttname"><a href="pheap_8h.html#a16d2f59279aad9419ebab05bf15d70b2">ph_free_node</a></div><div class="ttdeci">static void ph_free_node(pheap_t *heap, pheap_node_id_t id)</div><div class="ttdoc">Free a node that is not currently in the heap, but has been allocated.</div><div class="ttdef"><b>Definition:</b> pheap.h:245</div></div>
<div class="ttc" id="apheap_8h_html_a1fe718acebd018d31cab37071a65c61b"><div class="ttname"><a href="pheap_8h.html#a1fe718acebd018d31cab37071a65c61b">ph_clear</a></div><div class="ttdeci">void ph_clear(pheap_t *heap)</div><div class="ttdoc">Removes all nodes from the pairing heap.</div><div class="ttdef"><b>Definition:</b> pheap.c:27</div></div>
<div class="ttc" id="apheap_8h_html_a5f8a3b950288b90310216126750ae0ef"><div class="ttname"><a href="pheap_8h.html#a5f8a3b950288b90310216126750ae0ef">ph_post_alloc_init</a></div><div class="ttdeci">void ph_post_alloc_init(pheap_t *heap, uint max_nodes, pheap_comparator comparator, void *user_data)</div><div class="ttdoc">Initialize a statically allocated heap (ph_create() using the C heap). The heap member nodes must be ...</div><div class="ttdef"><b>Definition:</b> pheap.c:19</div></div>
<div class="ttc" id="apheap_8h_html_a799a2b5a1db608401482816d371a02a5"><div class="ttname"><a href="pheap_8h.html#a799a2b5a1db608401482816d371a02a5">ph_contains_node</a></div><div class="ttdeci">static bool ph_contains_node(pheap_t *heap, pheap_node_id_t id)</div><div class="ttdoc">Determine if the heap contains a given node. Note containment refers to whether the node is inserted ...</div><div class="ttdef"><b>Definition:</b> pheap.h:234</div></div>
<div class="ttc" id="apheap_8h_html_a852301ee2d8d4c3985dd61c14eb820a8"><div class="ttname"><a href="pheap_8h.html#a852301ee2d8d4c3985dd61c14eb820a8">ph_remove_and_free_node</a></div><div class="ttdeci">bool ph_remove_and_free_node(pheap_t *heap, pheap_node_id_t id)</div><div class="ttdoc">Remove and free an arbitrary node from the pairing heap. This is a more costly operation than removin...</div><div class="ttdef"><b>Definition:</b> pheap.c:82</div></div>
<div class="ttc" id="apheap_8h_html_a8ebc494b4ad703fe080bee5f18775fec"><div class="ttname"><a href="pheap_8h.html#a8ebc494b4ad703fe080bee5f18775fec">ph_remove_head</a></div><div class="ttdeci">pheap_node_id_t ph_remove_head(pheap_t *heap, bool free)</div><div class="ttdoc">Remove the head node from the pairing heap. This head node is the node which compares first in the lo...</div><div class="ttdef"><b>Definition:</b> pheap.c:76</div></div>
<div class="ttc" id="apheap_8h_html_a9723f40e88f36de3cd6cd955e3410600"><div class="ttname"><a href="pheap_8h.html#a9723f40e88f36de3cd6cd955e3410600">ph_peek_head</a></div><div class="ttdeci">static pheap_node_id_t ph_peek_head(pheap_t *heap)</div><div class="ttdoc">Returns the head node in the heap, i.e. the node which compares first, but without removing it from t...</div><div class="ttdef"><b>Definition:</b> pheap.h:179</div></div>
<div class="ttc" id="apheap_8h_html_aaac9dd2a264364a16a5753ba08c268cf"><div class="ttname"><a href="pheap_8h.html#aaac9dd2a264364a16a5753ba08c268cf">ph_dump</a></div><div class="ttdeci">void ph_dump(pheap_t *heap, void(*dump_key)(pheap_node_id_t id, void *user_data), void *user_data)</div><div class="ttdoc">Print a representation of the heap for debugging.</div></div>
<div class="ttc" id="apheap_8h_html_ab68363a744cae76cf6cce07fc60f4a5c"><div class="ttname"><a href="pheap_8h.html#ab68363a744cae76cf6cce07fc60f4a5c">ph_insert_node</a></div><div class="ttdeci">static pheap_node_id_t ph_insert_node(pheap_t *heap, pheap_node_id_t id)</div><div class="ttdoc">Inserts a node into the heap.</div><div class="ttdef"><b>Definition:</b> pheap.h:164</div></div>
<div class="ttc" id="apheap_8h_html_acde2f3fabd67330b56dbb8473387b272"><div class="ttname"><a href="pheap_8h.html#acde2f3fabd67330b56dbb8473387b272">ph_create</a></div><div class="ttdeci">pheap_t * ph_create(uint max_nodes, pheap_comparator comparator, void *user_data)</div><div class="ttdoc">Create a pairing heap, which effectively maintains an efficient sorted ordering of nodes....</div><div class="ttdef"><b>Definition:</b> pheap.c:11</div></div>
<div class="ttc" id="apheap_8h_html_aee7c4944ce644b92572b48b7d14fc65e"><div class="ttname"><a href="pheap_8h.html#aee7c4944ce644b92572b48b7d14fc65e">ph_remove_and_free_head</a></div><div class="ttdeci">static pheap_node_id_t ph_remove_and_free_head(pheap_t *heap)</div><div class="ttdoc">Remove the head node from the pairing heap. This head node is the node which compares first in the lo...</div><div class="ttdef"><b>Definition:</b> pheap.h:212</div></div>
<div class="ttc" id="apheap_8h_html_af631622b2fe9dbd39f39d457eef502d0"><div class="ttname"><a href="pheap_8h.html#af631622b2fe9dbd39f39d457eef502d0">ph_new_node</a></div><div class="ttdeci">static pheap_node_id_t ph_new_node(pheap_t *heap)</div><div class="ttdoc">Allocate a new node from the unused space in the heap.</div><div class="ttdef"><b>Definition:</b> pheap.h:143</div></div>
<div class="ttc" id="apico_8h_html"><div class="ttname"><a href="pico_8h.html">pico.h</a></div></div>
<div class="ttc" id="astructpheap__node_html"><div class="ttname"><a href="structpheap__node.html">pheap_node</a></div><div class="ttdef"><b>Definition:</b> pheap.h:51</div></div>
<div class="ttc" id="astructpheap_html"><div class="ttname"><a href="structpheap.html">pheap</a></div><div class="ttdef"><b>Definition:</b> pheap.h:62</div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->

	<script src="main.js"></script>
</body>
</html>